package cn.wolfcode.wms.domain;

import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSON;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class Product extends BaseDomain {
    //商品名称
    private String name;
    //商品编号
    private String sn;
    //成本价
    private BigDecimal costPrice;
    //市场价
    private BigDecimal salePrice;
    //商品图片
    private String imagePath;
    //商品介绍
    private String intro;
    //关联的品牌id
    private Long brandId;
    //品牌名称
    private String brandName;

    public String getJson(){
        Map<String,Object> json =new HashMap<>();
        json.put("name",name);
        json.put("id",getId());
        json.put("costPrice",costPrice);
        json.put("salePrice",salePrice);
        json.put("brandName",brandName);

        return JSON.toJSONString(json);
    }

    //获取小图
    public String getSmallImagePath() {
        if (StringUtils.isEmpty(imagePath)) {
            return "";
        }
        return this.imagePath.substring(0, this.imagePath.lastIndexOf(".")) + "_small"
                + this.imagePath.substring(this.imagePath.lastIndexOf("."));
    }
}